{% load i18n %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IC消费 PUSH SDK 模拟</title>
<script src="{{ MEDIA_URL }}/jslib/jquery.js"></script>
<style type="text/css">
	body,td,th {
		font-size: 12px;
	}
	body {
		margin-left: 0px;
		margin-top: 0px;
		margin-right: 0px;
		margin-bottom: 0px;
	}
	.an {
		height: 60px;
		width: 100px;
		font-size: 14px;
		font-weight: bold;
		color: #000000;
	}
	.select1 {
		width: 140px;
	}
   #result{ float:top; width:100%; height:100%; background: #eeeecc} 
    
</style>
</head>
<body>

<table width="90%" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#E1EBF4" class="tab">
  <a href="/manager/loadUrl/" > <<返回首页</a>
  <tr>

    <td bgcolor="#F7FCFD" colspan="2">
       	<input type="radio" name="radio" id="radio2" value="1" checked />
		<label id = "lable_redio2"for="Radio2"></label>
       	<label id = "pos_getdata" for="select"></label>
        <select class="select1" name="select_table_name" id="table_name" >
        <option value='PosLog'>消费明细</option>
        <option value='FullValue'>出纳明细</option>
        <option value='SidyLog'>补贴明细</option>
		<option value='PayDetail'>商品消费明细</option>
		<option value='TmPosLog'>计时消费记录</option>
		<option value='KeyDetail'>按键消费明细表</option>
        <option value='Mealtype'>设备餐别设置表</option>
		<option value='TimeSeg'>就餐时间段设置表</option>
		<option value='Fixed'>分段定值表</option>
		<option value='CardType'>卡类设置表</option>
		<option value='SubSidyLog'>下载待补贴表</option>
		<option value='PressKey'>按键金额设置表</option>
		<option value='StoreInfo'>商品信息设置表</option>
		<option value='UserInfo'>用户信息表</option>
		<option value='Template'>指纹模板表</option>
        </select>
		<label id = "lable_query_parm"for="radio2">附加条件</label><input style = "width:250px;" type="text"id="query_parm"/>
		
   		<a href="javascript:void(0);" onclick ="flush_dev();">刷新</a>
   	</td>
    <td rowspan="5" align="right" bgcolor="#F7FCFD">消费设备:
    <select class="select1" name="select" id="select" ></select>
    </td>
    <td rowspan="5" align="center" bgcolor="#F7FCFD">
    	<input class="an" type="button" name="button" id="id_submit" value="提交" onclick = "on_submit();"/>
    </td>
  </tr>


  <tr>
    <td bgcolor="#F7FCFD" colspan="2">
    	<input type="radio" name="radio" id="radio2" value="2" />
        <label id = "lable_redio1"for="Radio2"></label>
    	<input style = "width:250px;" type="text"id="dev_redis" value = "SN=5849791460183&type=pos&devno=1913"/>
		<a href="javascript:void(0);" onclick ="flush_dev();">刷新</a>
	</td>
  </tr>

  
 <tr>
	<td class="menu_item"><a href="{{request.dbapp_url}}pos/PosDevLog/">消费设备通信日志</a></td>
</tr>
  <tr>
 	<td class="menu_item"><a href="{{request.dbapp_url}}pos/CardSerial/">卡流水号记录表</a></td>
 </tr>
 
</table>
<br />
<table width="90%" height="400px" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#E1EBF4" class="tab">
  <tr height = "30px">
    <td bgcolor="#F7FCFD">返回结果</td>
  </tr>
  <tr>
    <td align="left" bgcolor="#F3F3F3">
	<div id="table_frame_div" scrolling="0" >
				<iframe src="" id="table_frame" frameborder="0" scrolling="0" width="100%" height="350"></iframe>
	</div>
	
    </td>
  </tr>
</table>
<script>

Date.prototype.format = function(format){
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}

if(/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}

for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}

////使用方法
//var now = new Date();
//var nowStr = now.format("yyyyMMddhhmmss");
//alert(nowStr)
//



	$(function(){
		var host =  document.location.host;
		var now = new Date();
		var nowStr = now.format("yyyyMMddhhmmss");
		$("#stime").val(nowStr)
		$("#etime").val(nowStr)
		$("#lable_redio2").html("读取设备表信息: http://"+host);
		$("#lable_redio1").html("获取设备未执行命令列表: http://"+host);
//		$("#lable_redio3").html("查询操作");
		set_sn();
		flush_dev();
	})
	
	function flush_dev(){
		$("#select").empty();
	    $.ajax({
	        url:"/manager/getDevInfo/?device_type=5",
	        type:"POST",
	        dataType:"json",
	        success:function(msg){
		    	if(!msg.data==null || !msg.data==""){
		    		data = msg.data
		    		for (i = 0; i<data.length;i++){
		    			$("#select").append('<option value="'+data[i][2]+'">'+data[i][2]+'//'+data[i][0]+'</option>');
		    		}
		    	}
	        }
	    });
	}
	function set_sn(){
		sn = Math.round(Math.random() * 10000000000000)
		$("#sn_bumber").val(sn)
		return;
	}
	function clear_(id){
		$("#"+id).val("")
		return;
	}
	function on_submit(){
		sn_num = ""
		url = ""
		check = $('input[name="radio"]:checked').val();
		if (check ==1){
			sn_ip = $("#select").val();
			dev_table_name = $("#table_name").val();
			q_parm = $("#query_parm").val()
//			http://192.168.10.141/data/?Action=Query&Table=UserInfo&Fields=*&Filter=
			if(q_parm == "")
			{
				url = "http://"+sn_ip+"/data/?Action=Query&Table="+dev_table_name+"&Fields=*&Filter="
			}
			else
			{
				url = "http://"+sn_ip+"/data/?Action=Query&Table="+dev_table_name+"&Fields=*&Filter="+q_parm
			}
	 	}
		else if (check ==2){
					sn_num = $("#select").find("option:selected").text().split("//")[1];
					//		http://192.168.10.92:8090/iclock/posrequest?SN=5849791460183&type=pos&devno=1913
					dev_redis_value = $("#dev_redis").val()
					if (dev_redis_value != "")
					{
						r_url = "SN="+sn_num+"&type=pos"
						$("#dev_redis").val(r_url)
						url = "/iclock/posrequest?"+r_url
						$("#getrequest").html(url)
					}
					else
					{
						alert("条件不能为空！")
						$("#dev_redis").val("SN=5849791460183&type=pos&devno=1913")
					}
			 	}
		
		else if (check ==3){
			sn_num = $("#select").val();
			quyer_type = $("#query_type").val();
			stime = $("#stime").val()
			etime = $("#etime").val()
			card_no = $("#card_value").val()
			url = "/iclock/pos_getrequest?querytype="+quyer_type+"&SN="+sn_num+"&card="+card_no+"&start="+stime+"&end="+etime
			}
				
	   $("#table_frame").attr("src",url)
//	    $.ajax({
//	        url:url,
//	        type:"POST",
//	        dataType:"html",
//            contentType: "application/x-www-form-urlencoded; text/xml;charset=utf-8",
//	        success:function(msg){
//                alert(msg)
//	            $("#result").html(msg);
//	        }
//	    });
	}
	</script>
</body>
</html>
